	function selectedOptPrice(v){
		var values=v.split('||');
		return values[0];
	}

	function getValueOptionID(v){
		var values=v.split('||');
		return values[0];
	}
	function getValueOptionPrice(optid){
		//get the select item's value
		var v=document.getElementById(optid).value;
		var values=v.split('||');
		return Number(values[1]);
	}
	function getValueOptionMemo(optid){
		//get the select item's value
		var v=document.getElementById(optid).value;
		var values=v.split('||');
		return values[2];
	}
	
	function selectandeditexplain(optid){
		var memo=getValueOptionMemo(optid);
		document.getElementById(optid.concat("editarea")).value=memo;
	}

	
	function previewprice(rate,size){
		//added by Bright @20080730 update the price	
		//get the origional item price

		var p=Number(document.getElementById("baseprice").value);
		var s=Number(size);
		for (i=0; i < s; i++){
			optionnum=i.toString()
			var op=Number(document.getElementById(optionnum.concat("newoptionprice")).value);	
			p+=op;
		}
		var r=Number(rate);
		var updatedprice = Math.round(p*r);
		document.getElementById("pricepreview").value = updatedprice;	
	}

	function replaceforphp(str){	
		//str = str.replace(/"/g, "&quot;");
		str = str.replace(/&/g, "and");
		//str = str.replace(/+/g, "plus");		
		//str = str.replace(/'/g, "&#39;");
		return str;
	}	
	
	
	function checkselection(){		
	
		var opt = document.getElementById('itemoptsstr').value;
		var opts = opt.split('||');
		var optsplit = new Array(opts.length)
		for (i=0; i < opts.length; i++){
			optsplit[i] = opts[i].split(':');
		}
		
		for (i=0; i < optsplit.length; i++){
			switch(optsplit[i][1]){
				case "DROP":
					var elem = document.getElementById(optsplit[i][0]);
					sel = elem.selectedIndex;
					
					if (elem.options[sel].text=="Please Select.."){
						alert('Please Select "'+optsplit[i][0]+'"');
					}

				break;
				
				case "SELECTANDEDIT":
					var elem = document.getElementById(optsplit[i][0]);
					sel = elem.selectedIndex;
					
					if (elem.options[sel].text=="Please Select.."){
						alert('Please Select "'+optsplit[i][0]+'"');
					}
										
				break;

			}
		}
	
	
	
	
	}
	
	
	function additemtocart(){	

		// Get hidden element
		var opt = document.getElementById('itemoptsstr').value;
 		// Parse itemopts to determine what fields we need to look for
		var opts = opt.split('||');
			
		// Now with our array opts[ind] = GARDENTYPE:DROPDOWN, split again
		var optsplit = new Array(opts.length)
		for (i=0; i < opts.length; i++){
			optsplit[i] = opts[i].split(':');
		}

		// Now optsplit[ind][ind] stores each of the properties we need to look for		
		// Lets get those elements values and build the opts string to return to the
		//  backend			
		
		var optsstring = '';
		for (i=0; i < optsplit.length; i++){
			switch(optsplit[i][1]){
				case "SELECT":
				case "DROPDOWN":
				case "DROP":
					var elem = document.getElementById(optsplit[i][0]);
					optsstring= optsstring + optsplit[i][0] + '::::';
					sel = elem.selectedIndex;
					
					if (elem.options[sel].text=="Please Select.."){
						alert('Please Select '+optsplit[i][0]);
						break;
					}
					
					res = getValueOptionID(elem.options[sel].value);

					optionnum=i.toString()
					var op=document.getElementById(optionnum.concat("newoptionprice")).value;	
					optsstring= optsstring + res + ',,,,' + op + '||||';		


				break;
				
				case "SELECTANDEDIT":
					var elem = document.getElementById(optsplit[i][0]);
					optsstring= optsstring + optsplit[i][0] + '::::';
					sel = elem.selectedIndex;
					
					if (elem.options[sel].text=="Please Select.."){
						alert('Please Select '+optsplit[i][0] );
						break;
					}
					
					res = getValueOptionID(elem.options[sel].value);
					
					
					optsstring= optsstring + res + '|||:::';		
					
					
					optionnum=i.toString()
					var op=document.getElementById(optionnum.concat("newoptionprice")).value;	
					
					optsstring= optsstring + res + ',,,,' + op + '|||:::';		
					opttext=replaceforphp(document.getElementById(optsplit[i][0].concat("editarea")).value);
					optsstring= optsstring + opttext  + '||||';			


					
				break;
	
				case "TEXT":
					opttext=replaceforphp(document.getElementById(optsplit[i][0]).value);
					optsstring= optsstring + optsplit[i][0] + '::::' +  opttext + '||||';
				break;
	
				case "TEXTAREA":
					opttext=replaceforphp(document.getElementById(optsplit[i][0]).value);
					optsstring= optsstring + optsplit[i][0] + '::::' + opttext + '||||';
				break;

	
				case "RADIO":
					var elem= document.getElementsByName(optsplit[i][0]);
					optsstring= optsstring + optsplit[i][0] + '::::';
					for (var j=0; j < elem.length; j++){
						if (elem[j].checked){
							optsstring = optsstring + elem[j].value;
						}
					}
					
					optionnum=i.toString()
					var op=document.getElementById(optionnum.concat("newoptionprice")).value;	
					optsstring= optsstring + ',,,,' + op + '||||';		
					
					
				break;
	
				case "CHECK":
					var elem = document.getElementsByName(optsplit[i][0]);
					optsstring = optsstring + optsplit[i][0] + '::::';
					for (var j=0; j < elem.length; j++){
						if (elem[j].checked){
							optsstring = optsstring + getValueOptionID(elem[j].value) + ';;;;';
						}
					}
					
					optsstring= optsstring.substring(0, optsstring.length-4);
					optsstring= optsstring + '||||';
				break;
				
				case "MULTI":
					var elem = document.getElementsByName(optsplit[i][0]);
					optsstring= optsstring + optsplit[i][0] + '::::';
					for (var j=0; j < elem.length; j++){
						if (elem[j].selected){
							optsstring= optsstring + getValueOptionID(elem[j].value) + ';;;;';
						}
					}
					
					optsstring= optsstring.substring(0, optsstring.length-4);
					optsstring= optsstring + '||||';				
				break;
			}
		}
		// Pull off last delimiter when all options are encoded
		optsstring = optsstring.substring(0, optsstring.length-4);
		var poststr = "trxntype=" + encodeURI('additemtocart') +
	 				  "&itemid=" + encodeURI(document.getElementById('item_id').value) +
					  "&qty=" + encodeURI(document.getElementById('qtytoenter').value) +
					  "&sessionid=" + encodeURI(document.getElementById('sessionid').value) + 
					  "&opts=" + encodeURI(optsstring);
		makePOSTRequest('assets/snippets/shoppingCart/cartmanager.php', poststr, 'additemtocart');
	}

	function showshipping(){
		if(document.getElementById('shipsamecheckbox').checked==true){
			document.getElementById('checkoutshippingdiv').style.display='none';
		}else{
			document.getElementById('checkoutshippingdiv').style.display='block';
		}
	}
	
	function ajaxLogin(){
		showBox();
	}


	
	
//Coded by Bright @ 20080801	
	function updateprice(type,optid,optionnum,rate,size,offset) {


		
		switch(type){
			case "drop":
				var p=getValueOptionPrice(optid);
				document.getElementById(optionnum.concat("newoptionprice")).value=p;
				previewprice(rate,size);
			break;
	
	
			case "radio":
				p = Number(offset);
				document.getElementById(optionnum.concat("newoptionprice")).value=p;
				previewprice(rate,size);
			break;
			
			case "selectandedit":
			
				//added by Bright @20080730 update the price	
				var minprice=30; // minicharges
				var basecharlenth=100; // price will not increase the char is not over this basecharlenth
				var priceincreaserate=5; // price will increase when char is over , this is example, price will increase 5 dollor when customer put more than 20 char.
				var pricechangelenth=20;  //this record how much will increased once number of char is over 
				var p=0;

				
				//var editedtext=document.getElementById(optid.concat("editarea")).value
				//editedtext=replaceforphp(editedtext);
				document.getElementById(optid.concat("editarea")).value=replaceforphp(document.getElementById(optid.concat("editarea")).value);
				var numofchar=document.getElementById(optid.concat("editarea")).value.length;
				document.getElementById(optid.concat("charcount")).value=numofchar;
	
				if(numofchar<=basecharlenth)	{ 
					p=minprice;
				}
				if(numofchar>basecharlenth)	{ 
					var a=numofchar-basecharlenth;
					var b=Math.ceil(a/pricechangelenth);
					p=b*priceincreaserate+minprice;
				}

				var r=Number(rate);
				var displayp=Math.round(p*r);
				//this if just for display
				document.getElementById(optid.concat("newprice")).value=displayp;
				//used for reference
				document.getElementById(optionnum.concat("newoptionprice")).value=p;	
				previewprice(rate,size);
	
			break;	
			
			case "check":
	
			break;
	
				
			case "multi":

			break;
		}	
	
				previewprice(rate,size);
	}

		

		
	function getLoginForm(){
		var poststr = "trxntype=" + encodeURI('getloginform');
	
		makePOSTRequest('assets/snippets/shoppingCart/cartmanager.php', poststr, 'getloginform');
	}
	
	function webLogin(){
		var poststr = "username=" + encodeURI(document.getElementById('usernamefield').value) +
				      "password=" + encodeURI(document.getElementById('passwordfield').value);
	
		makePOSTRequest('assets/snippets/weblogin/weblogin.processor.inc.php', poststr, 'weblogin');
	}
	
	function deletefromcart(id){
		var deleteconfirm = confirm("Do you really want to delete this item?");
		if (deleteconfirm == true){
			var poststr = "trxntype=" + encodeURI('deletefromcart') +
						  "&sessionid=" + encodeURI(document.getElementById('sessionid').value) +
					  	  "&detailid=" + encodeURI(id);
			makePOSTRequest('assets/snippets/shoppingCart/cartmanager.php', poststr, 'deletefromcart');
		}
	}
	
	function checklogin(){
		webShortname=document.getElementById('webShortname').value;

		webInternalKey=document.getElementById('webInternalKey').value;
		webEmail=document.getElementById('webEmail').value;
		webValid=document.getElementById('webValid').value;
		webUser=document.getElementById('webUser').value;
		var poststr = "trxntype=" + encodeURI('checklogin') + 
					  "&sessionid=" + encodeURI(document.getElementById('sessionid').value) + 
					  "&webShortname=" + encodeURI(webShortname) +
					  "&webInternalKey=" + encodeURI(webInternalKey) +
					  "&webEmail=" + encodeURI(webEmail) +
					  "&webValid=" + encodeURI(webValid) +
					  "&webUser=" + encodeURI(webUser);
		makePOSTRequest('assets/snippets/shoppingCart/cartmanager.php', poststr, 'checklogin');
	}
	function getPasswordForm(){
		document.getElementById('modal-title').innerHTML="Password Reminder";
		document.getElementById('loginform').style.display='none';
		document.getElementById('passwordreminderform').style.display='block';
	}
	
	function updatecartgrid(sessionid){
		var poststr = "trxntype=" + encodeURI('updatecartgrid') +
					  "&sessionid=" + encodeURI(document.getElementById('sessionid').value);
		makePOSTRequest('assets/snippets/shoppingCart/cartmanager.php', poststr, 'updatecartgrid');
	}

	function updatepaymentform(){
	
		document.getElementById('paymentnameoncard').style.backgroundColor='white';
		document.getElementById('paymentnamelabel').style.color='#54534C';		
	
		document.getElementById('paymentcardnumber').style.backgroundColor='white';
		document.getElementById('paymentcardnumberlabel').style.color='#54534C';		
		
		document.getElementById('paymentroutingnumber').style.backgroundColor='#white';
		document.getElementById('paymentroutinglabel').style.color='#54534C';
		
		document.getElementById('paymentcvvcode').style.backgroundColor='white';
		document.getElementById('paymentcvvcodelabel').style.color='#54534C';
	
		switch (document.getElementById('paymenttype').value){
			case "CC":
				document.getElementById('paymentcardtypefield').style.display='block';				
				document.getElementById('paymentcardtypelabel').style.display='block';
				document.getElementById('paymentpaytypefield').style.width='30%';
				document.getElementById('paymentroutingfield').style.display='none';
				document.getElementById('paymentroutinglabel').style.display='none';
				document.getElementById('paymentexpmofield').style.display='block';
				document.getElementById('paymentexpyrfield').style.display='block';
				document.getElementById('paymentexplabel').style.display='block';
				document.getElementById('paymentexplabel').style.display='block';
				document.getElementById('paymentcardnumberfield').style.display='block';
				document.getElementById('paymentcardnumberlabel').style.display='block';
				document.getElementById('paymentcvvcodefield').style.display='block';
				document.getElementById('paymentcvvcodelabel').style.display='block';
				document.getElementById('paymentnamefield').style.display='block';
				document.getElementById('paymentnamelabel').style.display='block';
				document.getElementById('paymentnamelabel').innerHTML='Name as it Appears on Card: ';
				document.getElementById('paymentinfodetail').style.height='160px';
				document.getElementById('paymentcardnumberfield').style.width='25%';
				document.getElementById('paymentcardnumberfield').style.paddingRight='148px';
				document.getElementById('processorderdiv').innerHTML= '<button id=\"creditbutton\" onClick=\"processcheckout(\'creditcard\');\">Process Order</button>';
				document.getElementById('processorderdiv').style.display='block';
				document.getElementById('processorderdiv-short').style.display='none';
			break;
	
			case "CK":
				document.getElementById('paymentcardnumberfield').style.paddingRight='148px';
				document.getElementById('paymentcardtypefield').style.display='none';				
				document.getElementById('paymentcardtypelabel').style.display='none';
				document.getElementById('paymentpaytypefield').style.width='55%';
				document.getElementById('paymentroutingfield').style.display='none';
				document.getElementById('paymentroutinglabel').style.display='none';
				document.getElementById('paymentexpmofield').style.display='none';
				document.getElementById('paymentexpyrfield').style.display='none';
				document.getElementById('paymentexplabel').style.display='none';
				document.getElementById('paymentexplabel').style.display='none';
				document.getElementById('paymentcardnumberfield').style.display='none';
				document.getElementById('paymentcardnumberlabel').style.display='none';
				document.getElementById('paymentcvvcodefield').style.display='none';
				document.getElementById('paymentcvvcodelabel').style.display='none';
				document.getElementById('paymentnamefield').style.display='none';
				document.getElementById('paymentnamelabel').style.display='none';
				document.getElementById('paymentinfodetail').style.height='40px';
				document.getElementById('processorderdiv-short').style.display='block';	
				document.getElementById('processorderdiv-short').style.width='20%';
				document.getElementById('processorderdiv-short').style.paddingTop='10px';
				document.getElementById('processorderdiv-short').innerHTML='<button id=\"checkbutton\" onClick=\"processcheckout(\'check\');\">Submit Order</button>';
				document.getElementById('processorderdiv').style.display='none';
			break;
	
			case "CR":
				document.getElementById('paymentcardtypefield').style.display='none';				
				document.getElementById('paymentcardtypelabel').style.display='none';
				document.getElementById('paymentpaytypefield').style.width='76%';
				document.getElementById('paymentroutingfield').style.display='none';
				document.getElementById('paymentroutinglabel').style.display='none';
				document.getElementById('paymentexpmofield').style.display='block';
				document.getElementById('paymentexpyrfield').style.display='block';
				document.getElementById('paymentexplabel').style.display='block';
				document.getElementById('paymentexplabel').style.display='block';
				document.getElementById('paymentcardnumberfield').style.display='block';
				document.getElementById('paymentcardnumberlabel').style.display='block';
				document.getElementById('paymentcvvcodefield').style.display='none';
				document.getElementById('paymentcvvcodelabel').style.display='none';
				document.getElementById('paymentnamefield').style.display='block';
				document.getElementById('paymentnamelabel').innerHTML='Name as it Appears on Acct:';
				document.getElementById('paymentnamelabel').style.display='block';
				document.getElementById('paymentinfodetail').style.height='160px';
				document.getElementById('paymentcardnumberfield').style.width='47.1%';
				document.getElementById('paymentcardnumberfield').style.paddingRight='148px';
				document.getElementById('processorderdiv').innerHTML='<button id=\"creditacctbutton\" onClick=\"processcheckout(\'creditaccount\');\">Process Order</button>';
				document.getElementById('processorderdiv').style.display='block';
				document.getElementById('processorderdiv-short').style.display='none';
			break;
	
			case "EC":
				document.getElementById('paymentcardtypefield').style.display='none';				
				document.getElementById('paymentcardtypelabel').style.display='none';
				document.getElementById('paymentpaytypefield').style.width='76%';
				document.getElementById('paymentexpmofield').style.display='none';
				document.getElementById('paymentexpyrfield').style.display='none';
				document.getElementById('paymentexplabel').style.display='none';
				document.getElementById('paymentexplabel').style.display='none';
				document.getElementById('paymentcardnumberfield').style.display='block';
				document.getElementById('paymentcardnumberlabel').style.display='block';
				document.getElementById('paymentcardnumberfield').style.paddingRight='262px';
				document.getElementById('paymentcvvcodefield').style.display='none';
				document.getElementById('paymentcvvcodelabel').style.display='none';
				document.getElementById('paymentnamefield').style.display='block';
				document.getElementById('paymentnamelabel').style.display='block';
				document.getElementById('paymentroutingfield').style.display='block';
				document.getElementById('paymentroutinglabel').style.display='block';
				document.getElementById('paymentnamelabel').innerHTML='Name as it Appears on Acct: ';
				document.getElementById('paymentinfodetail').style.height='165px';
				document.getElementById('paymentcardnumberfield').style.width='25%';
				document.getElementById('processorderdiv').innerHTML='<button id=\"echeckbutton\" onClick=\"processcheckout(\'echeck\');\">Process eCheck</button>';
				document.getElementById('processorderdiv').style.display='block';
				document.getElementById('processorderdiv-short').style.display='none';
				alert('Note: eChecks are currently no supported');
			break;
	
			case "GOOG":
				document.getElementById('paymentpaytypefield').style.display='none';
				document.getElementById('paymentcardtypefield').style.display='none';				
				document.getElementById('paymentcardtypelabel').style.display='none';
				document.getElementById('paymentpaytypefield').style.width='41%';
				document.getElementById('paymentroutingfield').style.display='none';
				document.getElementById('paymentroutinglabel').style.display='none';
				document.getElementById('paymentexpmofield').style.display='none';
				document.getElementById('paymentexpyrfield').style.display='none';
				document.getElementById('paymentexplabel').style.display='none';
				document.getElementById('paymentexplabel').style.display='none';
				document.getElementById('paymentcardnumberfield').style.display='none';
				document.getElementById('paymentcardnumberlabel').style.display='none';
				document.getElementById('paymentcvvcodefield').style.display='none';
				document.getElementById('paymentcvvcodelabel').style.display='none';
				document.getElementById('paymentnamefield').style.display='none';
				document.getElementById('paymentnamelabel').style.display='none';
				document.getElementById('paymentinfodetail').style.height='50px';
				document.getElementById('paymentcardnumberfield').style.paddingRight='148px';
				document.getElementById('processorderdiv-short').style.display='none';
				document.getElementById('processorderdiv-short').style.width='35%';
				document.getElementById('processorderdiv-short').style.paddingTop='0px';
				document.getElementById('processorderdiv').style.display='none';						
				document.getElementById('processorderdiv-short').innerHTML='';
				googlecart();					
			break;
	
			case "PAYPAL":
				document.getElementById('paymentpaytypefield').style.display='none';
				document.getElementById('paymentcardtypefield').style.display='none';				
				document.getElementById('paymentcardtypelabel').style.display='none';
				document.getElementById('paymentpaytypefield').style.width='51%';
				document.getElementById('paymentroutingfield').style.display='none';
				document.getElementById('paymentroutinglabel').style.display='none';
				document.getElementById('paymentexpmofield').style.display='none';
				document.getElementById('paymentexpyrfield').style.display='none';
				document.getElementById('paymentexplabel').style.display='none';
				document.getElementById('paymentexplabel').style.display='none';
				document.getElementById('paymentcardnumberfield').style.display='none';
				document.getElementById('paymentcardnumberlabel').style.display='none';
				document.getElementById('paymentcvvcodefield').style.display='none';
				document.getElementById('paymentcvvcodelabel').style.display='none';
				document.getElementById('paymentnamefield').style.display='none';
				document.getElementById('paymentnamelabel').style.display='none';
				document.getElementById('paymentinfodetail').style.height='45px';
				document.getElementById('paymentcardnumberfield').style.paddingRight='148px';
				document.getElementById('processorderdiv-short').style.display='none';
				document.getElementById('processorderdiv-short').style.width='25%';
				document.getElementById('processorderdiv-short').style.paddingTop='5px';
				document.getElementById('processorderdiv').style.display='none';
				paypalcart();
			break;	
		}
	}	
	
	function paypalcart(){
		var poststr = "trxntype=" + encodeURI('paypalcart') +
					  "&sessionid=" + encodeURI(document.getElementById('sessionid').value);
		makePOSTRequest('assets/snippets/shoppingCart/cartmanager.php', poststr, 'paypalcart');
	}
	
	function googlecart(){
		var poststr = "trxntype=" + encodeURI('googlecart') +
					  "&sessionid=" + encodeURI(document.getElementById('sessionid').value);
		makePOSTRequest('assets/snippets/shoppingCart/cartmanager.php', poststr, 'googlecart');
	}
		
	function processcheckout(checkouttype){	
		cardtype=document.getElementById('paymentcardtype').value;
		nameoncard=document.getElementById('paymentnameoncard').value;
		cardnum=document.getElementById('paymentcardnumber').value;
		routenum=document.getElementById('paymentroutingnumber').value;
		cvvcode=document.getElementById('paymentcvvcode').value;
		expmo=document.getElementById('paymentexpmo').value;
		expyr=document.getElementById('paymentexpyr').value;
		
		document.getElementById('paymentnameoncard').style.backgroundColor='white';
		document.getElementById('paymentnamelabel').style.color='#54534C';		
	
		document.getElementById('paymentcardnumber').style.backgroundColor='white';
		document.getElementById('paymentcardnumberlabel').style.color='#54534C';		
		
		document.getElementById('paymentroutingnumber').style.backgroundColor='white';
		document.getElementById('paymentroutinglabel').style.color='#54534C';
		
		document.getElementById('paymentcvvcode').style.backgroundColor='white';
		document.getElementById('paymentcvvcodelabel').style.color='#54534C';
		
		fieldstofix='';
		switch (checkouttype){
			case "creditaccount":
				if (nameoncard==""){
					fieldstofix = fieldstofix + 'Name on Account, ';
					document.getElementById('paymentnameoncard').style.backgroundColor='lightyellow';
					document.getElementById('paymentnamelabel').style.color='#820B15';
				}
				if (cardnum==""){
					fieldstofix = fieldstofix + 'Card Number, ';
					document.getElementById('paymentcardnumber').style.backgroundColor='lightyellow';
					document.getElementById('paymentcardnumberlabel').style.color='#820B15';
				}
				if (fieldstofix!=""){
					alert ('Please fix the following fields and try again: \n\n' + fieldstofix.substring(0, fieldstofix.length-2));
				}else {
					var poststr = 'trxntype=' + encodeURI('processcheckout') +
								  '&paymethod=' + encodeURI('CREDIT') + 
								  '&sessionid=' + encodeURI(document.getElementById('sessionid').value) + 
								  '&cardtype=' + encodeURI(cardtype) +
								  '&nameoncard=' + encodeURI(nameoncard) +
								  '&cardnum=' + encodeURI(cardnum) +
								  '&routenum=' + encodeURI(routenum) +
								  '&cvvcode=' + encodeURI(cvvcode) +
								  '&expmo=' + encodeURI(expmo) +
								  '&expyr=' + encodeURI(expyr);
					makePOSTRequest('assets/snippets/shoppingCart/cartmanager.php', poststr, 'processcheckoutpayment');	
				}
			break;
	
			case "check":
				var poststr = 'trxntype=' + encodeURI('processcheckout') +
							  '&paymethod=' + encodeURI('CHECK') + 
							  '&sessionid=' + encodeURI(document.getElementById('sessionid').value) + 
							  '&cardtype=' + encodeURI(cardtype) +
							  '&nameoncard=' + encodeURI(nameoncard) +
							  '&cardnum=' + encodeURI(cardnum) +
							  '&routenum=' + encodeURI(routenum) +
							  '&cvvcode=' + encodeURI(cvvcode) +
							  '&expmo=' + encodeURI(expmo) +
							  '&expyr=' + encodeURI(expyr);	
				makePOSTRequest('assets/snippets/shoppingCart/cartmanager.php', poststr, 'processcheckoutpayment');
			break;
	
			case "creditcard":
				if (nameoncard==""){
					fieldstofix = fieldstofix + 'Name on Card, ';
					document.getElementById('paymentnameoncard').style.backgroundColor='lightyellow';
					document.getElementById('paymentnamelabel').style.color='#820B15';
				}
				if (cardnum==""){
					fieldstofix = fieldstofix + 'Card Number, ';
					document.getElementById('paymentcardnumber').style.backgroundColor='lightyellow';
					document.getElementById('paymentcardnumberlabel').style.color='#820B15';
				}
				if (cvvcode==""){
					fieldstofix = fieldstofix + 'CVV2 Code, ';
					document.getElementById('paymentcvvcode').style.backgroundColor='lightyellow';
					document.getElementById('paymentcvvcodelabel').style.color='#820B15';
				}
				if (fieldstofix!=""){
					alert ('Please fix the following fields and try again: \n\n' + fieldstofix.substring(0, fieldstofix.length-2));
				}else {
					var poststr = 'trxntype=' + encodeURI('processcheckout') +
								  '&paymethod=' + encodeURI('CREDITCARD') + 
								  '&sessionid=' + encodeURI(document.getElementById('sessionid').value) + 
								  '&cardtype=' + encodeURI(cardtype) +
								  '&nameoncard=' + encodeURI(nameoncard) +
								  '&cardnum=' + encodeURI(cardnum) +

									  '&routenum=' + encodeURI(routenum) +
					 			  '&cvvcode=' + encodeURI(cvvcode) +
								  '&expmo=' + encodeURI(expmo) +
								  '&expyr=' + encodeURI(expyr);	
					makePOSTRequest('assets/snippets/shoppingCart/cartmanager.php', poststr, 'processcheckoutpayment');
				}
			break;
			
			case "echeck":
				if (nameoncard==""){
					fieldstofix = fieldstofix + 'Name on Account, ';
					document.getElementById('paymentnameoncard').style.backgroundColor='lightyellow';
					document.getElementById('paymentnamelabel').style.color='#820B15';
				}
				if (cardnum==""){
					fieldstofix = fieldstofix + 'Card Number, ';
					document.getElementById('paymentcardnumber').style.backgroundColor='lightyellow';
					document.getElementById('paymentcardnumberlabel').style.color='#820B15';
				}
				if (routenum==""){
					fieldstofix = fieldstofix + 'Routing Number, ';
					document.getElementById('paymentroutingnumber').style.backgroundColor='lightyellow';
					document.getElementById('paymentroutinglabel').style.color='#820B15';
				}
				if (fieldstofix!=""){
					alert ('Please fix the following fields and try again: \n\n' + fieldstofix.substring(0, fieldstofix.length-2));
				}else {
					var poststr = 'trxntype=' + encodeURI('processcheckout') +
								  '&paymethod=' + encodeURI('ECHECK') + 
								  '&sessionid=' + encodeURI(document.getElementById('sessionid').value) + 
								  '&cardtype=' + encodeURI(cardtype) +
								  '&nameoncard=' + encodeURI(nameoncard) +
								  '&cardnum=' + encodeURI(cardnum) +
								  '&routenum=' + encodeURI(routenum) +
								  '&cvvcode=' + encodeURI(cvvcode) +
								  '&expmo=' + encodeURI(expmo) +
								  '&expyr=' + encodeURI(expyr);	
					//makePOSTRequest('assets/snippets/shoppingCart/cartmanager.php', poststr, 'processcheckoutpayment');
					alert('Didn\'t I just say this wasn\'t implemented?  =) If you want to pay by check you\'ll have to mail it for now. ');
				}
			break;
	
			case "google":
				
			break;
	
			case "paypal":
				
			break;
		}
	}
	function checkshipandbill(){
		sessionid		= document.getElementById('sessionid').value;
		emailbilling	= document.getElementById('emailbilling').value;
		companybilling	= document.getElementById('companybilling').value;	
		lnamebilling	= document.getElementById('lnamebilling').value;
		fnamebilling	= document.getElementById('fnamebilling').value;
		addr1billing	= document.getElementById('addr1billing').value;
		addr2billing	= document.getElementById('addr2billing').value;
		citybilling		= document.getElementById('citybilling').value;
		statebilling	= document.getElementById('statebilling').value;
		zipbilling		= document.getElementById('zipbilling').value;
		phonebilling	= document.getElementById('phonebilling').value;
		extbilling		= document.getElementById('extbilling').value;
		faxbilling		= document.getElementById('faxbilling').value;

		companyship		= document.getElementById('companyship').value;	
		lnameship		= document.getElementById('lnameship').value;
		fnameship		= document.getElementById('fnameship').value;
		addr1ship		= document.getElementById('addr1ship').value;
		addr2ship		= document.getElementById('addr2ship').value;
		cityship		= document.getElementById('cityship').value;
		stateship		= document.getElementById('stateship').value;
		zipship			= document.getElementById('zipship').value;
		phoneship		= document.getElementById('phoneship').value;
		extship			= document.getElementById('extship').value;	
		
		document.getElementById('emailbilling').style.backgroundColor='white';
		document.getElementById('emaillabel').style.color='#54534C';
		document.getElementById('fnamebilling').style.backgroundColor='white';
		document.getElementById('fnamelabel').style.color='#54534C';
		document.getElementById('lnamebilling').style.backgroundColor='white';
		document.getElementById('lnamelabel').style.color='#54534C';
		document.getElementById('addr1billing').style.backgroundColor='white';
		document.getElementById('addr1label').style.color='#54534C';
		document.getElementById('citybilling').style.backgroundColor='white';
		document.getElementById('citylabel').style.color='#54534C';
		document.getElementById('statebilling').style.backgroundColor='white';
		document.getElementById('statelabel').style.color='#54534C';
		document.getElementById('zipbilling').style.backgroundColor='white';
		document.getElementById('ziplabel').style.color='#54534C';
		document.getElementById('phonebilling').style.backgroundColor='white';
		document.getElementById('phonelabel').style.color='#54534C';

		document.getElementById('fnameship').style.backgroundColor='white';
		document.getElementById('shipfnamelabel').style.color='#54534C';
		document.getElementById('lnameship').style.backgroundColor='white';
		document.getElementById('shiplnamelabel').style.color='#54534C';
		document.getElementById('addr1ship').style.backgroundColor='white';
		document.getElementById('shipaddr1label').style.color='#54534C';
		document.getElementById('cityship').style.backgroundColor='white';
		document.getElementById('shipcitylabel').style.color='#54534C';
		document.getElementById('stateship').style.backgroundColor='white';
		document.getElementById('shipstatelabel').style.color='#54534C';
		document.getElementById('zipship').style.backgroundColor='white';
		document.getElementById('shipziplabel').style.color='#54534C';
	
		fieldstofix="";
		if (emailbilling==""){
			fieldstofix= fieldstofix + "Billing Email, ";
			document.getElementById('emailbilling').style.backgroundColor='lightyellow';
			document.getElementById('emaillabel').style.color='#820B15';
		}
		if (fnamebilling==""){
			fieldstofix= fieldstofix + "Billing First Name, ";
			document.getElementById('fnamebilling').style.backgroundColor='lightyellow';
			document.getElementById('fnamelabel').style.color='#820B15';
		}
		if (lnamebilling==""){
			fieldstofix= fieldstofix + "Billing Last Name, ";
			document.getElementById('lnamebilling').style.backgroundColor='lightyellow';
			document.getElementById('lnamelabel').style.color='#820B15';
		}
		if (addr1billing==""){
			fieldstofix= fieldstofix + "Billing Address, ";
			document.getElementById('addr1billing').style.backgroundColor='lightyellow';
			document.getElementById('addr1label').style.color='#820B15';
		}
		if (citybilling==""){
			fieldstofix= fieldstofix + "Billing City, ";
			document.getElementById('citybilling').style.backgroundColor='lightyellow';
			document.getElementById('citylabel').style.color='#820B15';
		}
		if (statebilling==""){
			fieldstofix= fieldstofix + "Billing State, ";
			document.getElementById('statebilling').style.backgroundColor='lightyellow';
			document.getElementById('statelabel').style.color='#820B15';
		}
		if (zipbilling==""){
			fieldstofix= fieldstofix + "Billing Zip, ";
			document.getElementById('zipbilling').style.backgroundColor='lightyellow';
			document.getElementById('ziplabel').style.color='#820B15';
		}
		if (phonebilling==""){
			fieldstofix= fieldstofix + "Billing Phone, ";
			document.getElementById('phonebilling').style.backgroundColor='lightyellow';
			document.getElementById('phonelabel').style.color='#820B15';
		}
	
		if (document.getElementById('shipsamecheckbox').checked==false){
			if (fnameship==""){
				fieldstofix= fieldstofix + "Shipping First Name, ";
				document.getElementById('fnameship').style.backgroundColor='lightyellow';
				document.getElementById('shipfnamelabel').style.color='#820B15';
	
			}
			if (lnameship==""){
				fieldstofix= fieldstofix + "Shipping Last Name, ";
				document.getElementById('lnameship').style.backgroundColor='lightyellow';
				document.getElementById('shiplnamelabel').style.color='#820B15';
			}
			if (addr1ship==""){
				fieldstofix= fieldstofix + "Shipping Address, ";
				document.getElementById('addr1ship').style.backgroundColor='lightyellow';
				document.getElementById('shipaddr1label').style.color='#820B15';
			}
			if (cityship==""){
				fieldstofix= fieldstofix + "Shipping City, ";
				document.getElementById('cityship').style.backgroundColor='lightyellow';
				document.getElementById('shipcitylabel').style.color='#820B15';
			}
			if (stateship==""){
				fieldstofix= fieldstofix + "Shipping State, ";
				document.getElementById('stateship').style.backgroundColor='lightyellow';
				document.getElementById('shipstatelabel').style.color='#820B15';
			}
			if (zipship==""){
				fieldstofix= fieldstofix + "Shipping Zip, ";
				document.getElementById('zipship').style.backgroundColor='lightyellow';
				document.getElementById('shipziplabel').style.color='#820B15';
			}
		}
		if (fieldstofix != ""){
			fieldstofix = fieldstofix.substring(0, fieldstofix.length-2);
			alert ('You must fix the following fields to continue: \n' + fieldstofix);
		}else {
			var poststr= "trxntype=" + encodeURI('updatecartforcheckout') +
						 "&sessionid=" + encodeURI(sessionid) + 
						 "&emailbilling=" + encodeURI(emailbilling) +
						 "&fnamebilling=" + encodeURI(fnamebilling) +
						 "&lnamebilling=" + encodeURI(lnamebilling) +
						 "&addr1billing=" + encodeURI(addr1billing) +
						 "&addr2billing=" + encodeURI(addr2billing) +
						 "&citybilling=" + encodeURI(citybilling) +
						 "&statebilling=" + encodeURI(statebilling) +
						 "&zipbilling=" + encodeURI(zipbilling) +
						 "&phonebilling=" + encodeURI(phonebilling) +
						 "&extbilling=" + encodeURI(extbilling) +
						 "&faxbilling=" + encodeURI(faxbilling) +
						 "&companybilling=" + encodeURI(companybilling) +
						 "&companyship=" + encodeURI(companyship) +
						 "&fnameship=" + encodeURI(fnameship) +
						 "&lnameship=" + encodeURI(lnameship) +
						 "&addr1ship=" + encodeURI(addr1ship) +
						 "&addr2ship=" + encodeURI(addr2ship) +
						 "&cityship=" + encodeURI(cityship) +
						 "&stateship=" + encodeURI(stateship) +
						 "&zipship=" + encodeURI(zipship) +
						 "&phoneship=" + encodeURI(phoneship) +
						 "&extship=" + encodeURI(extship);	
			makePOSTRequest('assets/snippets/shoppingCart/cartmanager.php', poststr, 'updatecartforcheckout');
		}
	}
	
	function checksignup(){

		sessionid		= document.getElementById('sessionid').value;
		username		= document.getElementById('username').value;
		email			= document.getElementById('email').value;
		company			= document.getElementById('company').value;	
		lname			= document.getElementById('lname').value;
		fname			= document.getElementById('fname').value;
		addr1			= document.getElementById('addr1').value;
		addr2			= document.getElementById('addr2').value;
		city			= document.getElementById('city').value;
		state			= document.getElementById('state').value;
		zip				= document.getElementById('zip').value;
		country 		= document.getElementById('country').value;
		phone			= document.getElementById('phone').value;
		ext				= document.getElementById('ext').value;
		fax				= document.getElementById('fax').value;
		password		= document.getElementById('password').value;
		confirmpassword = document.getElementById('confirmpassword').value;
	
		fullname 		= fname + ' ' + lname;

		document.getElementById('username').style.backgroundColor='white';
		document.getElementById('usernamelabel').style.color='#54534C';
		document.getElementById('password').style.backgroundColor='white';
		document.getElementById('passwordlabel').style.color='#54534C';
		document.getElementById('confirmpassword').style.backgroundColor='white';
		document.getElementById('confirmpasswordlabel').style.color='#54534C';
		document.getElementById('email').style.backgroundColor='white';
		document.getElementById('emaillabel').style.color='#54534C';
		document.getElementById('fname').style.backgroundColor='white';
		document.getElementById('fnamelabel').style.color='#54534C';
		document.getElementById('lname').style.backgroundColor='white';
		document.getElementById('lnamelabel').style.color='#54534C';
		document.getElementById('addr1').style.backgroundColor='white';
		document.getElementById('addr1label').style.color='#54534C';
		document.getElementById('city').style.backgroundColor='white';
		document.getElementById('citylabel').style.color='#54534C';
		document.getElementById('state').style.backgroundColor='white';
		document.getElementById('statelabel').style.color='#54534C';
		document.getElementById('zip').style.backgroundColor='white';
		document.getElementById('ziplabel').style.color='#54534C';
		document.getElementById('countrylabel').style.color='#54534C';
		document.getElementById('phone').style.backgroundColor='white';
		document.getElementById('phonelabel').style.color='#54534C';

		fieldstofix="";
		if (username==""){
			fieldstofix= fieldstofix + "Username, ";
			document.getElementById('username').style.backgroundColor='lightyellow';
			document.getElementById('usernamelabel').style.color='#820B15';
		}
		if (email==""){
			fieldstofix= fieldstofix + "Email, ";
			document.getElementById('email').style.backgroundColor='lightyellow';
			document.getElementById('emaillabel').style.color='#820B15';
		}
		if (fname==""){
			fieldstofix= fieldstofix + "First Name, ";
			document.getElementById('fname').style.backgroundColor='lightyellow';
			document.getElementById('fnamelabel').style.color='#820B15';
		}
		if (lname==""){
			fieldstofix= fieldstofix + "Last Name, ";
			document.getElementById('lname').style.backgroundColor='lightyellow';
			document.getElementById('lnamelabel').style.color='#820B15';
		}		
		if (addr1==""){
			fieldstofix= fieldstofix + "Address, ";
			document.getElementById('addr1').style.backgroundColor='lightyellow';
			document.getElementById('addr1label').style.color='#820B15';
		}
		if (city==""){
			fieldstofix= fieldstofix + "City, ";
			document.getElementById('city').style.backgroundColor='lightyellow';
			document.getElementById('citylabel').style.color='#820B15';
		}
		if (state==""){
			fieldstofix= fieldstofix + "State, ";
			document.getElementById('state').style.backgroundColor='lightyellow';
			document.getElementById('statelabel').style.color='#820B15';
		}
		if (zip==""){
			fieldstofix= fieldstofix + "Zip, ";
			document.getElementById('zip').style.backgroundColor='lightyellow';
			document.getElementById('ziplabel').style.color='#820B15';
		}
		if (country==""){
			fieldstofix= fieldstofix + "Country, ";
			document.getElementById('country').style.backgroundColor='lightyellow';
			document.getElementById('countrylabel').style.color='#820B15';
		}
		if (phone==""){
			fieldstofix= fieldstofix + "Phone, ";
			document.getElementById('phone').style.backgroundColor='lightyellow';
			document.getElementById('phonelabel').style.color='#820B15';
		}

		// Check password requirements
		if (password == ""){
			fieldstofix= fieldstofix + "Password, ";
			document.getElementById('password').style.backgroundColor='lightyellow';
			document.getElementById('passwordlabel').style.color='#820B15';	
			document.getElementById('confirmpassword').style.backgroundColor='lightyellow';
			document.getElementById('confirmpasswordlabel').style.color='#820B15';	
		}else if (confirmpassword== ""){
			fieldstofix= fieldstofix + "Confirm Password, ";
			document.getElementById('confirmpassword').style.backgroundColor='lightyellow';
			document.getElementById('confirmpasswordlabel').style.color='#820B15';	
		} else if (password.length < 7){
 			fieldstofix = fieldstofix.substring(0, fieldstofix.length-2);
			fieldstofix = fieldstofix + '\n\n' + 'Password length is too short...try again!  ';	
			document.getElementById('password').style.backgroundColor='lightyellow';
			document.getElementById('passwordlabel').style.color='#820B15';	
			document.getElementById('confirmpassword').style.backgroundColor='lightyellow';
			document.getElementById('confirmpasswordlabel').style.color='#820B15';	
		} else if (confirmpassword != password) {
			fieldstofix = fieldstofix.substring(0, fieldstofix.length-2);
			fieldstofix = fieldstofix + '\n\n' + 'Passwords do not match...please try again!  ';	
			document.getElementById('password').style.backgroundColor='lightyellow';
			document.getElementById('passwordlabel').style.color='#820B15';	
			document.getElementById('confirmpassword').style.backgroundColor='lightyellow';
			document.getElementById('confirmpasswordlabel').style.color='#820B15';	
		}
	
		if (fieldstofix != ""){
			fieldstofix = fieldstofix.substring(0, fieldstofix.length-2);
			alert ('You must fix the following fields to continue: \n' + fieldstofix);
		}else {
			var poststr= "trxntype=" + encodeURI('createuseraccount') +
						 "&sessionid=" + encodeURI(sessionid) + 
						 "&email=" + encodeURI(email) +
						 "&fname=" + encodeURI(fname) +
						 "&lname=" + encodeURI(lname) +
						 "&addr1=" + encodeURI(addr1) +
						 "&addr2=" + encodeURI(addr2) +
						 "&city=" + encodeURI(city) +
						 "&state=" + encodeURI(state) +
						 "&zip=" + encodeURI(zip) +
						 "&country=" + encodeURI(country) +
						 "&phone=" + encodeURI(phone) +
						 "&ext=" + encodeURI(ext) +
						 "&fax=" + encodeURI(fax) +
						 "&company=" + encodeURI(company) +
						 "&username=" + encodeURI(username) +
						 "&password=" + encodeURI(hex_md5(password));
			makePOSTRequest('assets/snippets/shoppingCart/cartmanager.php', poststr, 'createuseraccount');
		}
	}	
	
	function checkusername(){

		var poststr= "trxntype=" + encodeURI('checkusername') +
					 "&username=" + encodeURI(document.getElementById('username').value);
	
		makePOSTRequest('assets/snippets/shoppingCart/cartmanager.php', poststr, 'checkusername');
	}

	function checkemail(){
		var poststr= "trxntype=" + encodeURI('checkemail') +
					 "&email=" + encodeURI(document.getElementById('email').value);
		makePOSTRequest('assets/snippets/shoppingCart/cartmanager.php', poststr, 'checkemail');
	}

	function ajaxreturnprocessor(name){
		if (name == 'checkusername'){
			if (http_request.responseText=="TRUE" || http_request.responseText=="\nTRUE"){
				document.getElementById('username').style.backgroundColor='lightyellow';
				document.getElementById('usernamelabel').style.color='#820B15';
				alert('The username is taken, please try again.');
				document.getElementById('username').value='';
			}else {
				document.getElementById('username').style.backgroundColor='white';
				document.getElementById('usernamelabel').style.color='#54534C';				
			}
			return http_request.responseText;
		}
		if (name == 'checkemail'){
			if (http_request.responseText=="TRUE" || http_request.responseText=="\nTRUE"){
				document.getElementById('email').style.backgroundColor='lightyellow';
				document.getElementById('emaillabel').style.color='#820B15';
				alert('This email address is already taken, please try again.');
				document.getElementById('email').value='';
			}else if (http_request.responseText=="INVALID" || http_request.responseText=="\nINVALID"){
				document.getElementById('email').style.backgroundColor='lightyellow';
				document.getElementById('emaillabel').style.color='#820B15';
				alert('This email address does not seem valid...please enter it again.');
				document.getElementById('email').value='';			
			}else {
				document.getElementById('email').style.backgroundColor='white';
				document.getElementById('emaillabel').style.color='#54534C';				
			}
			return http_request.responseText;
		}
		if (name == 'additemtocart'){
//			document.getElementById('cartnotification').innerHTML=http_request.responseText
			location.href = 'index.php?id=4002';
		} 
		if (name == 'getloginform'){
			document.getElementById('modal-title').innerHTML="Login";
			document.getElementById('inner-box').innerHTML=http_request.responseText;
		}
		if (name == 'weblogin'){
		}
	
		if (name == 'deletefromcart'){
			updatecartgrid(document.getElementById('sessionid'));
		}
		if (name == 'createuseraccount'){
			window.location = "index.php?id=4005";
		}
		if (name == 'updatecartforcheckout'){
			window.location = "index.php?id=4006";
		}
		if (name == 'googlecart'){
			document.getElementById('processorderdiv-short').style.display='none';
			document.getElementById('processorderdiv-short').innerHTML=http_request.responseText;
			document.getElementById('processorderdiv-short').style.display='block';
			document.getElementById('paymentpaytypefield').style.display='block';
		}
		if (name == 'paypalcart'){
			document.getElementById('processorderdiv-short').style.display='none';
			document.getElementById('processorderdiv-short').innerHTML=http_request.responseText;
			document.getElementById('processorderdiv-short').style.display='block';
			document.getElementById('paymentpaytypefield').style.display='block';
		}
		if (name == 'processcheckoutpayment'){
			window.location = "index.php?id=4004";
		}
		if (name == 'checklogin'){
			switch (http_request.responseText){
				case "\nMATCH":
					window.location = "index.php?id=4003";
				break;
	
				case "MATCH":
					window.location = "index.php?id=4003";
				break;

				case "\nSTALESESSION":
					window.location = "index.php?id=4005";
				break;
	
				case "STALESESSION":
					window.location = "index.php?id=4005";
				break;
	
				case "\nTRYAGAINORCREATE":
					window.location = "index.php?id=4005";
				break;
	
				case "TRYAGAINORCREATE":
					window.location = "index.php?id=4005";
	
				case "\nNODATA":
					window.location = "index.php?id=4005";
				break;	
			
				case "NODATA":
					window.location = "index.php?id=4005";
				break;
			}
		}
		if (name == 'updatecartgrid'){
			document.getElementById('shoppingcartdiv').innerHTML=http_request.responseText;
		}
	}
	
	function gotoLogin(){
		window.location = "index.php?id=4003";
	}
	
    function makePOSTRequest(url, parameters, name){

        http_request = false;
        if (window.XMLHttpRequest){
           http_request = new XMLHttpRequest();
           if (http_request.overrideMimeType){
              http_request.overrideMimeType('text/html');
           }
        }else if (window.ActiveXObject){
              try {
                    http_request = new ActiveXObject("Msxml2.XMLHTTP");
              } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e){}
              }
        }
        if (!http_request) {
           alert('Cannot create XMLHTTP instance');
           return false;
        }

        http_request.open('POST', url, true);
        http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        http_request.setRequestHeader("Content-length", parameters.length);
        http_request.setRequestHeader("Connection", "close");
        http_request.send(parameters);
        nameval=name;
        http_request.onreadystatechange= alertContents();
	    }

    function alertContents() {
        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
                ajaxreturnprocessor(nameval);
            } else {
                alert('There was a problem with the request: ' + http_request.responseText);
            }
        } else {
            setTimeout('alertContents()', 4);
        }
    }	